import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import eslintPlugin from "vite-plugin-eslint";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import IconsResolver from "unplugin-icons/resolver";
import Icons from 'unplugin-icons/vite';
import Inspect from 'vite-plugin-inspect';
import path from "path";
// import styleImport, { AndDesignVueResolve,ElementPlusResolve } from 'vite-plugin-style-import';

// https://vitejs.dev/config/
export default defineConfig({
	resolve: {
		alias: { "@": path.resolve(__dirname, "./src") },
	},
	plugins: [
		vue(),
		// eslintPlugin({
		// 	include: ["src/**/*.ts", "src/**/*.vue", "src/*.ts", "src/*.vue"],
		// }),
		AutoImport({
			imports: ["vue", "vue-router", "pinia"],
			include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/],
			dts: "src/auto-imports.d.ts",
			eslintrc: {
				enabled: false, // Default `false`
				filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json`
				globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
			},
			resolvers: [
				ElementPlusResolver(),
				AntDesignVueResolver(),
				IconsResolver({ prefix: "Icon" }),
			],
		}),
		Components({
			// dirs 指定组件所在位置，默认为 src/components
			// 可以让我们使用自己定义组件的时候免去 import 的麻烦
			dirs: ["src/components/"],
			// 配置需要将哪些后缀类型的文件进行自动按需引入
			extensions: ["vue", "md"],
			// 解析的 UI 组件库，这里以 Element Plus 和 Ant Design Vue 为例
			resolvers: [
				ElementPlusResolver(),
				AntDesignVueResolver(), // 自动注册图标组件
				IconsResolver({
					enabledCollections: ["ep"],
				}),
				Icons({
					autoInstall: true,
				  }),
				  Inspect(),
			],
		}),
	],
	server: {
		port: 3000,
		open: true,
		proxy: {
			"/api": {
				// target: "http://81.70.207.80:3001/",
				target: "http://localhost:3001/",
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ""),
			},
		},
	},
});
